﻿using System.Security.Cryptography;
using System.Text;

namespace Yamfinder.Service
{
    public class CryptoService : ICryptoService
    {
        //Basic encrpytion for now, can use salting when bothered but this is good enough for intranet
        public string GetHash(string value)
        {
            //Get hash value for the value parameter
            var hashedValue = new byte[Encoding.UTF8.GetByteCount(value)];
            Encoding.UTF8.GetBytes(value, 0, value.Length, hashedValue, 0);
            byte[] hash = null;
            using (var hasher = new SHA512Managed())
            {
                hash = hasher.ComputeHash(hashedValue);
            }

            return Encoding.UTF8.GetString(hash);
        }

        public bool Match(string value, string hash)
        {
            //Hash the value
            var result = GetHash(value);

            //compare
            return result == hash;
        }
    }
}